﻿// --------------------------------------------------------------------------------------------------------------------
// (c) Copyright Microsoft Corporation.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
// <Credits>
// David Anson
// http://blogs.msdn.com/b/delay/archive/2010/09/08/never-do-today-what-you-can-put-off-till-tomorrow-deferredloadlistbox-and-stackpanel-help-windows-phone-7-lists-scroll-smoothly-and-consistently.aspx
// </Credits>
// --------------------------------------------------------------------------------------------------------------------


namespace WP7Contrib.View.Controls
{
    using System.Windows;
    using System.Windows.Controls;

    /// <summary>
    /// Implements a subclass of ListBoxItem that is used in conjunction with
    /// the DeferredLoadListBox to defer the loading of off-screen items.
    /// </summary>
    public class DeferredLoadListBoxItem : ListBoxItem
    {
        private object _maskedContent;
        private DataTemplate _maskedContentTemplate;

        internal bool Masked { get; set; }

        internal void MaskContent()
        {
            if (!Masked)
            {
                _maskedContent = Content;
                _maskedContentTemplate = ContentTemplate;
                Content = null;
                ContentTemplate = null;
                Masked = true;
            }
        }

        internal void UnmaskContent()
        {
            if (Masked)
            {
                ContentTemplate = _maskedContentTemplate;
                Content = _maskedContent;
                _maskedContentTemplate = null;
                _maskedContent = null;
                Masked = false;
            }
        }
    }
}
